package com.ak.assets;

import com.ak.cluster.AssetIndex;
import com.ak.cluster.GameObject;
import com.ak.cluster.GameWorld;


//This is ugly! Extend off of a tile class!
public class Grid extends GameObject{

	public GameWorld mWorld;
	public Grid(GameWorld world)
	{
		//NO SHAPE,

		super();
		mWorld = world;
		textureID = 1;
		assetTexture = assignTexture(AssetIndex.gridTexture);
		position.x = 0;
		position.y = 35;
		scale.x = 0.5f;
		scale.y = 0.5f;
		chosenRenderSetting = RenderOptions.ALPHA.code;

		assetMesh = buildMesh(assetMesh, assetTexture);

		chosenBodyType = PhysicsBodyOptions.DYNAMIC.code;

		mWorld.addObject(this);

	}

	public void createGrid(int size)
	{
		//r = 33   r is the distance from the tip to the point of a flat face.
		//s = 96
		//l = 55
		//Thanks to:
		//http://www.gamedev.net/page/resources/_/reference/programming/sweet-snippets/coordinates-in-hexagon-based-tile-maps-r1800
		//offset everyother row.

		//for sliding down.
		int s = 96;

		//for offset
		int r = 28;

		//lateralMovement
		int l = 55;

		int hexX = 600,hexY = 400;
		int initX = 600;
		//batch.draw(texHexagon,hexX,hexY);
		for(int i = 1;i <= size; i++ )
		{
			if(i % 2 != 0)
			{
				for(int j = 0; j<=size-2; j++)
				{
					//mAssetManager.createAsset(mFilename,hexX,hexY,true);
					//batch.draw(texHexagon,hexX,hexY,0,0,texHexagon.getWidth(),texHexagon.getWidth());
					hexX-=l+(r*2);
					if(j == size-2)
					{
						hexY-=s;
						hexX+=(r*2);
					}
				}
			}
			else
			{
				for(int j = 0; j<=size-1; j++)
				{
					//mAssetManager.createAsset(mFilename,hexX,hexY,true);

					//batch.draw(texHexagon,hexX,hexY,0,0,texHexagon.getWidth(),texHexagon.getWidth());
					hexX+=l+(r*2);
					if(j == size-1)
					{
						hexY-=s;
						hexX=initX;
					}
				}
			}
		}

	}

	@Override
	protected void update() {
		position = this.objectBody.getPosition();
	}

	@Override
	protected void dispose() {
		// TODO Auto-generated method stub
		assetTexture.dispose();
		assetMesh.dispose();
	}

}
